﻿using System;
using System.Collections.Generic;
using System.Text;
using Csla;
using Csla.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;

namespace buildingLib.daily
{
    /// <summary>
    /// 档案名称
    /// </summary>
    [Serializable()]
    public class ArchiveTypes : NameValueListBase<string, string>
    {
        public static ArchiveTypes GetArchiveTypes()
        {
            return DataPortal.Fetch<ArchiveTypes>();
        }

        private void DataPortal_Fetch()
        {
            Database db = SQLDatabase.GetDatabase();
            DbCommand dbcom = db.GetSqlStringCommand("select [name] from (select distinct([name]) from archive) t order by len([name]) desc");
            using (SafeDataReader dr = new SafeDataReader(db.ExecuteReader(dbcom)))
            {
                this.IsReadOnly = false;
                while (dr.Read())
                {
                    if (dr.GetString(0) != string.Empty)
                        this.Add(new NameValuePair(
                          dr.GetString(0), dr.GetString(0)));
                }
                this.IsReadOnly = true;
            }
        }
    }
}
